package com.cskaoyan.controller.wx_search;

import com.cskaoyan.bean.wx_resp.WxRespVo;
import com.cskaoyan.bean.wx_search.Keyword;
import com.cskaoyan.bean.wx_search.vo.IndexVo;
import com.cskaoyan.service.wx_search.WxSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类<code>Doc</code>用于：TODO
 *
 * @author Acher
 * @version 1.0
 * @date 2021-10-22
 */
@RequestMapping("wx/search")
@RestController
public class WxSearchController {

    @Autowired
    WxSearchService wxSearchService;

    @RequestMapping("index")
    public WxRespVo index() {
        IndexVo index = wxSearchService.index();
        return WxRespVo.ok(index);
    }

    @RequestMapping("helper")
    // http://localhost:8083/wx/search/helper?keyword=r
    public WxRespVo helper(Keyword keyword) {// 可以设置keyword非空
        List<String> keywords = wxSearchService.helper(keyword.getKeyword());
        return WxRespVo.ok(keywords);
    }

    // http://localhost:8083/wx/goods/list?keyword=%E6%97%A5%E5%BC%8F&page=1&limit=20&sort=name&order=desc&categoryId=0

    @PostMapping("clearhistory")
    // http://localhost:8083/wx/search/clearhistory
    public WxRespVo clearhistory() {
        if (!wxSearchService.clearhistory())
            return WxRespVo.error("deleted fail");
        return WxRespVo.ok();
    }

}
